﻿/*
LICENCE___________________________________________________________________
    Copyright (C) 2012 Reverdy Sylvain

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License along
    with this program; if not, write to the Free Software Foundation, Inc.,
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
FIN LICENCE______________________________________________________________
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace Merise_designer.Donnees
{
    
    class CL_Associations
    {
        private CL_CAD cad = new CL_CAD();

        public void add(Merise_designer.Objets.CL_Association asso)
        {
            string req = @"INSERT INTO ASSOCIATIONS (ID_ASSO, NOM_ASSO, CODE_ASSO, LARG_ASSO, HAUT_ASSO, POSITION_ASSO) VALUES('" + asso.Id + "', '" + asso.Name + "','" + asso.CodeName + "','" + asso.Largeur + "','" + asso.Hauteur + "', '" + CadTools.getPosition(asso) + "') ";
            cad.ActionsRows(req, true);
        }

        public String getAdd(Merise_designer.Objets.CL_Association asso)
        {
            return @"INSERT INTO ASSOCIATIONS (ID_ASSO, NOM_ASSO, CODE_ASSO, LARG_ASSO, HAUT_ASSO, POSITION_ASSO) VALUES('" + asso.Id + "', '" + asso.Name + "','" + asso.CodeName + "','" + asso.Largeur + "','" + asso.Hauteur + "', '" + CadTools.getPosition(asso) + "');";
        }


        public void update(Objets.CL_Association asso)
        {
            string req = @"UPDATE ASSOCIATIONS SET NOM_ASSO='" + asso.Name + "',  CODE_ASSO='" + asso.CodeName + "',  LARG_ASSO='" + asso.Largeur + "',  HAUT_ASSO='" + asso.Hauteur + "',  POSITION_ASSO='" + CadTools.getPosition(asso) + "' WHERE ID_ASSO='" + asso.Id + "'";
            cad.ActionsRows(req, true);
        }

        public void deleteAll()
        {
            string req = @"DELETE FROM ASSOCIATIONS";
            cad.ActionsRows(req, true);
        }
        public String getDeleteAll()
        {
           return @"DELETE FROM ASSOCIATIONS;";
        }
        public void delete(string id)
        {
            string req = @"DELETE FROM ASSOCIATIONS WHERE ID_ASSO='" + id + "'";
            cad.ActionsRows(req, true);
        }

        public DataSet selectAll(string monJeu)
        {
            string req = @"SELECT ID_ASSO, NOM_ASSO, CODE_ASSO, LARG_ASSO, HAUT_ASSO, POSITION_ASSO FROM ASSOCIATIONS";
            return cad.GetRows(req, monJeu);
        }

        public DataSet select(string id, string monJeu)
        {
            string req = @"SELECT ID_ASSO, NOM_ASSO, CODE_ASSO, LARG_ASSO, HAUT_ASSO, POSITION_ASSO FROM ASSOCIATIONS WHERE ID_ASSO='" + id + "'";
            return cad.GetRows(req, monJeu);
        }

    }
}
